"""Plot RNA Degradation

.. helpdoc::


"""

"""<widgetXML>
    <name>Plot RNA Degradation</name>
    <icon>Default.png</icon>
    <tags> 
        <tag>Microarray</tag> 
    </tags>
    <summary>Plot RNA Degradation model fit of affy data.</summary>
    <author>
        <authorname>Kyle R Covington</authorname>
        <authorcontact>kyle@red-r.org</authorcontact>
    </author>
</widgetXML>
"""


"""
<name>Plot RNA Degradation</name>
<author>Generated using Widget Maker written by Kyle R. Covington</author>
<RFunctions>affy:plotAffyRNAdeg</RFunctions>
<tags>Affy QC</tags>
<icon></icon>
"""
from OWRpy import * 
import redRGUI 
import libraries.affy.signalClasses as signals
class RedRplotAffyRNAdeg(OWRpy): 
    settingsList = []
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)
        self.require_librarys(["affy"])
        self.RFunctionParam_rna_deg_obj = ''
        
        """.. rrsignals::"""
        self.inputs.addInput('rnadeg', "RNA Degradation Object", signals.DegFit.DegFit, self.processrna_deg_obj)
        
        self.RFunctionParamcols_radioButtons =  redRRadioButtons(self.controlArea,  label = "Color:", buttons = ['Yes', 'No'], setChecked = 'Yes')
        self.RFunctionParamtransform_comboBox =  redRComboBox(self.controlArea,  label = "Transform Plot:", items = ["Shift and Scale, shift.scale", "Shift only, shift.only", 'Neither'])
        redRCommitButton(self.bottomAreaRight, "Commit", callback = self.commitFunction)
    def processrna_deg_obj(self, data):
        if data:
            self.RFunctionParam_rna_deg_obj=data.getData()
            #self.data = data
            self.commitFunction()
        else:
            self.RFunctionParam_rna_deg_obj=''
    def commitFunction(self):
        if unicode(self.RFunctionParam_rna_deg_obj) == '': return
        injection = []
        if unicode(self.RFunctionParamcols_radioButtons.getChecked()) == 'Yes':
            string = 'cols=rainbow(length('+self.RFunctionParam_rna_deg_obj+'), 0, 1)'
            injection.append(string)
        else:
            string = 'cols = NULL'
            injection.append(string)
        if unicode(self.RFunctionParamtransform_comboBox.currentText()) != 'Neither':
            text = unicode(self.RFunctionParamtransform_comboBox.currentText())
            text = text.split(',')[1].strip()
            string = 'transform=\"'+unicode(text)+'\"'
            injection.append(string)
        inj = ','.join(injection)
        self.R('plotAffyRNAdeg(rna.deg.obj='+unicode(self.RFunctionParam_rna_deg_obj)+','+inj+')')
